package com.fly.container.mode;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author Mr.Fu
 * @date 2024/10/7 下午4:30
 */
public class NewInstance {

    public static void main(String[] args) throws Exception {
        String classPath = "com.fly.container.mode.SkuService";
        Class<?> clazz = Class.forName(classPath);
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            System.out.println(field.getName());
        }
        System.out.println("========================");
        Object bean = clazz.getDeclaredConstructor().newInstance();
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method method : declaredMethods) {
            int parameterCount = method.getParameterCount();
            if (parameterCount == 0) {
                continue;
            }
            Class<?>[] parameterTypes = method.getParameterTypes();
            Object[] invokeMethodParamTypes = new Object[parameterTypes.length];
            for (int i = 0; i < parameterTypes.length; i++) {
                Class<?> paramType = parameterTypes[i];
                String typeName = paramType.getTypeName();
                if ("java.lang.Long".equals(typeName)) {
                    invokeMethodParamTypes[i] = 1L;
                }

                if ("java.lang.String".equals(typeName)) {
                    invokeMethodParamTypes[i] = "test";
                }
            }
            Object abc = method.invoke(bean, invokeMethodParamTypes);
        }
//        skuService.setSkuName("娃哈哈纯净水 550ml");
        System.out.println(bean);
    }
}
